package IMIC.NGUYENVANTINH.ARRAY.EXCERCISE.EX5;

public class Models {

	public int[] BubbleSort(int[] Array) {
        int temp, counter, index;
        
        for(counter=0; counter<Array.length-1; counter++) { //Loop once for each element in the array.
            for(index=0; index<Array.length-1-counter; index++) { //Once for each element, minus the counter.
                if(Array[index] > Array[index+1]) { //Test if need a swap or not.
                    temp = Array[index]; //These three lines just swap the two elements:
                    Array[index] = Array[index+1];
                    Array[index+1] = temp;
                }
            }
            
        }
        return Array;
    }

	public int[] SelectSort(int[] arr){
		for (int i = arr.length - 1; i >= 1; i--){
	         // Find the maximum in the list[0..i]
	         int currentMax = arr[0];
	         int currentMaxIndex = 0;
	         {for (int j = 1; j <= i; j++) {
	          if (currentMax < arr[j]) {
	             currentMax = arr[j];
	            currentMaxIndex = j;
	           }
	         } 
	         // Swap list[i] with list[currentMaxIndex] if necessary;
	         if (currentMaxIndex != i) {
	        	 arr[currentMaxIndex] = arr[i];
	        	 arr[i] = currentMax;
	         }
	       }
	    
		}
		return arr;
	}
	public int[] BubbleSorts(int[] myarr){
		
		for(int i=0;i<myarr.length-1;i++){
			for(int j=0;j<myarr.length-1-i;j++){
				if(myarr[i]>myarr[i+1]){
					int temp = myarr[i];
					myarr[i] = myarr[i+1];
					myarr[i+1] = temp;
				}
			}
		}
		return myarr;
		
	}
	
	
}
